<import template="/panel/_header" />
<div class="page-container">
    <div class="main-content">
        <div class="page-title">

            <div class="title-env">
                <h1 class="title">修改昵称</h1>
                <p class="description">修改账户的昵称, 用于展示</p>
            </div>

            <div class="breadcrumb-env">
                <ol class="breadcrumb bc-1">
                    <li>
                        <a href="/member"><i class="fa-home"></i>主页</a>
                    </li>
                    <li>
                        <a href="javascript:;">我的信息</a>
                    </li>
                    <li class="active">
                        <strong>修改昵称</strong>
                    </li>
                </ol>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <i class="fa fa-angle-right"></i>&nbsp;修改昵称
                    </div>
                    <div class="panel-body">
                        <div class="form-group">
                            <label for="nickname-old" class="control-label">旧昵称：</label>
                            <input type="text" class="form-control disabled" id="nickname-old" placeholder="{$user->nickname}" value="{$user->nickname}" disabled="disabled">
                            <label for="nickname-new" class="control-label">新的昵称：</label>
                            <input type="text" class="form-control" id="nickname-new" placeholder="{$user->nickname}">
                        </div>
                    </div>
                    <button class="btn btn-info btn-block" id="submit-nickname">确定修改</button>
                </div>
            </div>
        </div>
        <script>
            $(document).ready(function(){
                $("#submit-nickname").click(function(){
                    var but = $(this);
                    var nickname = $("#nickname-new").val();
                    if(nickname == null || nickname == '') {
                        showToastr("你不填写就想改真的好吗?", 0, 2000);
                        return;
                    }
                    but.attr('disabled', 'true').addClass('disabled');
                    $.ajax({
                        type:"POST",
                        url:"/member/changeNickname.json",
                        data:{nickname:$("#nickname-new").val()},
                        dataType:"json",
                        success:function(result){
                            but.removeAttr('disabled').removeClass('disabled');
                            if(result.code != 200) {
                                showToastr(result.message, 0);
                                return;
                            }
                            showToastr(result.data.message, 0);
                            $("#nickname-old").val($("#nickname-new").val());
                            $("#nickname-new").val('');
                        },
                        error:function(jqXHR){
                            showToastr("发生错误："+jqXHR.status, 0);
                            but.removeAttr('disabled').removeClass('disabled');
                        }
                    })
                });
            });
        </script>
        <import template="/panel/_copyright" />
    </div>
</div>
<import template="/panel/_footer" />